﻿<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="SPThumbnailExtender.ViewerThumbnail"
    RegistrationId="101"
    RegistrationType="List"
    Location="CommandUI.Ribbon"
    Title="Show Viewer">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Documents.Groups._children">
          <Group Id="Ribbon.Documents.ShowViewer"
          Title="Viewer"
          Template="Ribbon.Templates.Flexible2"
          Sequence="50">
            <Controls Id="Ribbon.Documents.ShowViewer.Controls._children">
              <Button
                Id="Ribbon.Documents.ShowViewer.Run"
                Command="Show_Viewer"
                Image32by32="/_layouts/images/SPThumbnailExtender/thumbext32.png"
                Image16by16="/_layouts/images/SPThumbnailExtender/thumbext16.png"
                LabelText="Show Viewer"
                TemplateAlias="o1"
                
              />
            </Controls>
          </Group>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Documents.Scaling._children">
          <MaxSize Id="Ribbon.Documents.ShowViewer.MaxSize"
          GroupId="Ribbon.Documents.ShowViewer"
          Size="LargeMedium" />
        </CommandUIDefinition>

      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="Show_Viewer"
                          CommandAction="javascript:function ShowViewer()
                          {
                            var ctx = SP.ClientContext.get_current();
                            var items = SP.ListOperation.Selection.getSelectedItems(ctx);
                            var selectedItems = ''; 
                            var k; 
                            for (k in items) { 
                                selectedItems = items[k].id;
                                OpenDialog(ctx,'/_layouts/SPThumbnailExtender/ThumbSilverlight.aspx?ID=' + selectedItems +'&amp;source=' +SP.ListOperation.Selection.getSelectedList() );
                                break;
                              } 
                          
                          }
                          function OpenDialog(context,docurl) {
                            var options = {
                                url:  context.get_url() + docurl,
                                width: 800,
                                height: 600,
                                showMaximize: true
                              };
                            SP.UI.ModalDialog.showModalDialog(options);
                          };
                          ShowViewer();"
                          EnabledScript="javascript:function oneOrMoreEnable() { 
                          var items = SP.ListOperation.Selection.getSelectedItems(); 
                          var ci = CountDictionary(items); 
                          return (ci == 1); 
                          } oneOrMoreEnable();" 

                          />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>
